package com.swjd.bean;
import java.sql.*;
public class book {
	  private String userid;   //用户号
	  private int countnum;    //经过几站
	  private double dingjin;  //订阅
	  private double afford;   //费用
	  private String startplace;//起始地
	  private String destination; //终点站

	  public String getuserId() {
		    return userid;
		  }
		  public void setuserId(String uid) {
		    this.userid = uid;
		  }                                                             
		  public String getStartplace() {
			    return startplace;
			  }
			  public void setStartplace(String sp) {
			    this.startplace = sp;
			  }
			  public String getDestination() {
			    return destination;
			  }
			  public void setDestination(String md) {
			    this.destination = md;
			  }
      public int getCountnum() {
			    return countnum;
			  }
	  public void setCountnum(int num) {
			    this.countnum=num;
			  }
	  public double getSub() {
		    return dingjin;
		  }
	  public void setSub(double dj) {
		    this.dingjin= dj;
		  }
	  public double getAfford() {
		    return afford;
		  }
	  public void setAfford(double afford) {
		    this.afford = afford;
		  }

	  
	  
	  public boolean hasLogin(String tid,String uid){   //检查该订票信息是否已经存在 
	  	boolean f=true;
	   String sql="select user_id,ticket_id from ticket" +
	   		" where ticket_id ='"+tid+"' and user_id='"+uid+"' ";
	  	sqlBean db =new sqlBean();
	  	try{
	  	ResultSet rs=db.executeQuery(sql);
	  	if(rs.next()){ f=false;}
	  	else{ f=true;}
	  	}catch(Exception e){ e.getMessage();}
	  	return f;
	  	                       }
	  	                       
	  public ResultSet  getBook(){
			String sql="select user_id,book.start_station,book.dest_station,subscription,countnumber,afford," +
					"train_id,type,price from book,ticket" +
					" where book.start_station=ticket.start_station and book.dest_station=ticket.dest_station";
			sqlBean db= new sqlBean();
			ResultSet rs = db.executeQuery(sql);
			 return rs;
			                         } 
	  
			                         
   /* public void updateBook(){
	    	String sql="update book SET " +
	    			   "startplace='"+startplace+"',destination='"+destination+"'," +
	    			   "starttime='"+starttime+"',remain='"+shengyu+"'," +
	    			   "price='"+price+"',seat='"+seat+"',train_id='"+trainid+"'"+
	                   " where ticket_id='"+ticketid+"' ";
	                 sqlBean db= new sqlBean();
	                 db.executeInsert(sql);
	                 
	    	}	*/    
	  			                         		                                                 	                       	                       
	  public void deleteBook(){
	    
	    	String sql="delete from book where start_station='"+startplace+"' and " +
	    			" user_id='"+userid+"' and dest_station='"+destination+"'";
	    	sqlBean db= new sqlBean();
	    	db.executeDelete(sql);
	    	}                       
	  	       
	  public int deleteBook(String userid,String ticketid){
	    	int num=0;
	    	String sql="delete from book where ticket_id ='"+ticketid+"' and " +
			           " user_id='"+userid+"' ";
	    	sqlBean db= new sqlBean();
	    	num=db.executeDelete(sql);
	    	return num;
	    	}                        	                       
    
}
